<?php
declare(strict_types=1);

namespace App\Controller\v1;

use App\Controller\AbstractController;
use App\Request\Web\CreateTagRequest;
use App\Request\Web\PublishArticleRequest;
use App\Resource\Web\TagResource;
use App\Service\Web\TagService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PatchMapping;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller('/api/web/v1/tags')]
class TagController extends AbstractController
{
    #[Inject]
    private TagService $tagService;

    #[GetMapping('names')]
    public function getTags()
    {
        return $this->tagService->getTags();
    }

    #[PostMapping('')]
    public function store(CreateTagRequest $request)
    {
        $validated = $request->validated();

        $tag = $this->tagService->store($validated);

        return new TagResource($tag);
    }

    #[DeleteMapping('{id}')]
    public function destroy(int $id)
    {
        $this->tagService->destroy($id);

        return [];
    }
}